/* -----------------------------------------------------------------------------
 * PROJECT    : lwf_handlers
 * FILE       : WpTypeThree.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Sep 23, 2011  mycodetalks			       Created
 */
package net.lwf.handler.wp.helper.general;

import java.util.Map;

import net.lwf.entity.QuestionInfo;
import net.lwf.handler.wp.helper.IWordProblem;
import net.lwf.hibernate.entity.wp.WpData;
import net.lwf.number.util.RandomNumberGenerator;

/**
 * This type generates two values which are to be added to get the result.
 * (val2 * val1) - val1
 */
public class WpMultiplySubtractImpl extends ArithmaticWp implements IWordProblem {

	public QuestionInfo generate(WpData wpdata) {
		
		Map<Integer, String[]> valuedata = extractMultipleData(wpdata.getDataInput());
		String[] minmax = valuedata.get(new Integer(1));
		int val1 = RandomNumberGenerator.generate(Integer.parseInt(minmax[0]), Integer.parseInt(minmax[1]));
		 minmax = valuedata.get(new Integer(2));
		int val2 = RandomNumberGenerator.generate(Integer.parseInt(minmax[0]), Integer.parseInt(minmax[1]));
		
		String question = wpdata.getProblem();
		//Compute the answer
		String answer = String.valueOf((val2 * val2) + val1);
		
		String[] svalues = {String.valueOf(val1), String.valueOf(val2)};
		
		return setQuestionInfo(question, wpdata.getReplacements(), svalues, answer, false);
	}

}